using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FetCo.Data;
using ADESSA.Business;
using ADESSA.Entities;
using FetCo.Framework;
using FetCo.Web;
using System.IO;
using System.Collections.Generic;

public partial class ProductList : System.Web.UI.Page
{
    protected long idcat
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["idcat"] == null || HttpContext.Current.Request.QueryString["idcat"] == "0")
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["idcat"]);
        }
    }
    protected long idSubcat
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["idSubcat"] == null || HttpContext.Current.Request.QueryString["idSubcat"] == "0")
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["idSubcat"]);
        }
    }
    protected long idSubSubcat
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["idSubSubcat"] == null || HttpContext.Current.Request.QueryString["idSubSubcat"] == "0")
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["idSubSubcat"]);
        }
    }
    protected long country
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["country"] == null || HttpContext.Current.Request.QueryString["country"] == "0")
                return long.MinValue;
            else
                return long.Parse(HttpContext.Current.Request.QueryString["country"]);
        }
    }
    protected string key
    {
        get
        {
            if (HttpContext.Current.Request.QueryString["key"] == null)
                return null;
            else
                return HttpContext.Current.Request.QueryString["key"];
        }
    }
    string Goldmember = "";
    string Online = "";
    string qrycat = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        LoadSubSubCat();
        LoadProductSell();

        hrfTap1.HRef = string.Format("ProductList.aspx?idcat={0}&idSubcat={1}&idSubSubcat={2}", idcat, idSubcat, idSubSubcat);
        hrfTap2.HRef = string.Format("Productbuylist.aspx?idcat={0}&idSubcat={1}&idSubSubcat={2}", idcat, idSubcat, idSubSubcat);
    }
    #region LoadSubSubcat
    private void LoadSubSubCat()
    {
        if (this.idSubSubcat != long.MinValue)
        {
            ProductCat _ProductCatSubSub = ProductCatService.GetProductCat(this.idSubSubcat);
            ProductCat _ProductCatSub = ProductCatService.GetProductCat(_ProductCatSubSub.Parrentid);
            ltrcontenthrftitle.Text = "<img src='images/icon_arrow2.gif' width='9' height='9' /><a href='ProductList.aspx?idSubcat=" + _ProductCatSub.ProCateID + "' class='bold'> " + _ProductCatSub.Name + "</a>";
            ProductCat _ProductCatCat = ProductCatService.GetProductCat(_ProductCatSub.Parrentid);
            ltrCatpro.Text = _ProductCatCat.Name;
            hrfCatpro.HRef = "ProductList.aspx?idcat=" + _ProductCatCat.ProCateID + "";
        }

        ProductCatCollection _ProductCatCollection = new ProductCatCollection();
        if (this.idcat != long.MinValue)
        {
            ProductCat _ProductCatCat = ProductCatService.GetProductCat(this.idcat);
            ltrCatpro.Text = _ProductCatCat.Name;
            hrfCatpro.HRef = "ProductList.aspx?idcat=" + this.idcat + "";
            Criteria cri = new Criteria();
            cri.add(ProductCat._Table + "." + ProductCatColumns.Parrentid, this.idcat, Condition.EQUAL, Condition.AND);
            ProductCatCollection _ProductCatCollections = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, cri.Criter);
            string qry = "";
            if (_ProductCatCollections.Count > 0)
            {
                foreach (ProductCat _ProductCat in _ProductCatCollections)
                {
                    qry += _ProductCat.ProCateID + ",";
                }
            }
            Criteria crit = new Criteria();
            string sqry = "";
            if (qry != "")
                sqry = crit.Criter + "And Parrentid IN(" + qry.TrimEnd(',') + ")";
            else
                sqry = crit.Criter;
            _ProductCatCollection = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, sqry);
        }
        else if (this.idSubcat != long.MinValue)
        {
            ProductCat _ProductCat = ProductCatService.GetProductCat(this.idSubcat);
            ltrcontenthrftitle.Text = "<img src='images/icon_arrow2.gif' width='9' height='9' /><a href='ProductList.aspx?idSubcat=" + this.idSubcat + "' class='bold'> " + _ProductCat.Name + "</a>";
            ProductCat _ProductCatCat = ProductCatService.GetProductCat(_ProductCat.Parrentid);
            ltrCatpro.Text = _ProductCatCat.Name;
            hrfCatpro.HRef = "ProductList.aspx?idcat=" + _ProductCatCat.ProCateID + "";

            Criteria cri = new Criteria();
            cri.add(ProductCat._Table + "." + ProductCatColumns.Parrentid, this.idSubcat, Condition.EQUAL, Condition.AND);
            _ProductCatCollection = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, cri.Criter);
        }

        ArrayList Arrylisttop = new ArrayList();
        ArrayList Arrylistmores = new ArrayList();
        if (_ProductCatCollection.Count > 0)
        {
            for (int i = 0; i < _ProductCatCollection.Count; i++)
            {
                if (i < 13)
                {
                    Arrylisttop.Add(_ProductCatCollection[i]);
                }
                else
                {
                    Arrylistmores.Add(_ProductCatCollection[i]);
                }
            }
            rptSubSubCat.DataSource = Arrylisttop;
            rptSubSubCat.DataBind();
            rptSubSubCatOther.DataSource = Arrylistmores;
            rptSubSubCatOther.DataBind();
        }
    }
    protected void rptSubSubCat_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ProductCat _ProductCat = (ProductCat)e.Item.DataItem;
            HtmlAnchor hrfSubSubcat = (HtmlAnchor)e.Item.FindControl("hrfSubSubcat");
            Literal ltrsubsubcat = (Literal)e.Item.FindControl("ltrsubsubcat");
            hrfSubSubcat.HRef = string.Format("ProductList.aspx?idcat={0}&idSubcat={1}&idSubSubcat={2}", this.idcat, this.idSubcat, _ProductCat.ProCateID);
            ltrsubsubcat.Text = _ProductCat.Name;
            if (this.idSubSubcat == _ProductCat.ProCateID)
            {
                hrfSubSubcat.Attributes.Add("class", "red bold");
            }
        }
    }
    protected void rptSubSubCatOther_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ProductCat _ProductCat = (ProductCat)e.Item.DataItem;
            HtmlAnchor hrfSubSubcat = (HtmlAnchor)e.Item.FindControl("hrfSubSubcat");
            Literal ltrsubsubcat = (Literal)e.Item.FindControl("ltrsubsubcat");
            hrfSubSubcat.HRef = string.Format("ProductList.aspx?idcat={0}&idSubcat={1}&idSubSubcat={2}", this.idcat, this.idSubcat, _ProductCat.ProCateID);
            ltrsubsubcat.Text = _ProductCat.Name;
            if (this.idSubSubcat != long.MinValue)
            {
                hrfSubSubcat.Attributes.Add("class", "hookCss itemCssFlag qrPCatp red bold");
            }
        }
    }
    #endregion
    #region  Load Product Sell
    int PageSize = 0;
    string str = "";
    string qryMember = "";
    private void LoadProductSell()
    {
        //LoadTab1();
        #region get Online

        if (ckonline.Checked == true)
        {
            Criteria criter = new Criteria();
            //criter.add(Member._Table + "." + MemberColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            MemberCollection _MemberCollection = MemberService.GetMemberListByParam(Member._Table + "." + MemberColumns.MemberID, OrderDirection.ASC, criter.Criter);
            if (_MemberCollection.Count > 0)
            {
                foreach (Member _Member in _MemberCollection)
                {
                    if (!string.IsNullOrEmpty(_Member.Other))
                    {
                        if (_Member.Status == true)
                        {
                            if (Utility.GetYahooStatus(_Member.Other))
                            {
                                qryMember += _Member.MemberID + ",";
                            }
                        }
                        else
                        {
                            if (Utility.GetSkypeStatus(_Member.Other))
                            {
                                qryMember += _Member.MemberID + ",";
                            }
                        }
                    }

                }
            }
        }
        #endregion
        #region Page size
        int OutTotal = 0;
        int OutTotalNotGold = 0;
        if (PageSize == 10)
        {
            hyperlinkPager.PageSize = PageSize;
            page1.Attributes.Add("class", "cur");
            page2.Attributes.Add("class", "");
            page3.Attributes.Add("class", "");
        }
        else if (PageSize == 20)
        {
            hyperlinkPager.PageSize = PageSize;
            page1.Attributes.Add("class", "");
            page2.Attributes.Add("class", "cur");
            page3.Attributes.Add("class", "");
        }
        else if (PageSize == 40)
        {
            hyperlinkPager.PageSize = PageSize;
            page1.Attributes.Add("class", "");
            page2.Attributes.Add("class", "");
            page3.Attributes.Add("class", "cur");
        }
        else
        {
            hyperlinkPager.PageSize = 10;
            page1.Attributes.Add("class", "cur");
            page2.Attributes.Add("class", "");
            page3.Attributes.Add("class", "");
        }
        #endregion

        ProductSellCollection _ProductSellCollectionGold = new ProductSellCollection();
        if (this.idcat != long.MinValue)
        {
            Criteria cri = new Criteria();
            cri.add(ProductCat._Table + "." + ProductCatColumns.Parrentid, this.idcat, Condition.EQUAL, Condition.AND);
            ProductCatCollection _ProductCatCollections = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, cri.Criter);
            string qry = "";
            if (_ProductCatCollections.Count > 0)
            {
                foreach (ProductCat _ProductCat in _ProductCatCollections)
                {
                    qry += _ProductCat.ProCateID + ",";
                }
            }
            Criteria critt = new Criteria();
            string sqrys = "";
            if (qry != "")
                sqrys = critt.Criter + "And Parrentid IN(" + qry.TrimEnd(',') + ")";
            else
                sqrys = critt.Criter;
            ProductCatCollection _ProductCatCollection = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, sqrys);

            if (_ProductCatCollection.Count > 0)
            {
                foreach (ProductCat _ProductCat in _ProductCatCollection)
                {
                    qrycat += _ProductCat.ProCateID + ",";
                }
            }
            #region  Get Not gold Member
            Criteria crit = new Criteria();
            crit.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            crit.add(Member._Table + "." + MemberColumns.GoldMember, 0, Condition.EQUAL, Condition.AND);
            string sqry = "";
            if (qrycat != "")
            {
                if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                    sqry = crit.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
                else
                    sqry = crit.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
            }
            else
                sqry = crit.Criter + "And PRODUCTSELL.CatId IN(0)";
            ProductSellCollection _ProductSellCollectionNotGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqry, out OutTotalNotGold);
            #endregion
            #region  Get gold Member
            Criteria critr = new Criteria();
            critr.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            critr.add(Member._Table + "." + MemberColumns.GoldMember, 1, Condition.EQUAL, Condition.AND);
            string sqryr = "";
            if (qrycat != "")
            {
                if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                    sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
                else
                    sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
            }
            else
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(0)";
            _ProductSellCollectionGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqryr, out OutTotal);
            if (ckgoldmember.Checked == false)
            {
                for (int i = 0; i < _ProductSellCollectionNotGold.Count; i++)
                {
                    _ProductSellCollectionGold.Add(_ProductSellCollectionNotGold[i]);
                }
                OutTotal = OutTotal + OutTotalNotGold;
            }            
            #endregion

        }
        else if (this.idSubcat != long.MinValue)
        {

            Criteria cri = new Criteria();
            cri.add(ProductCat._Table + "." + ProductCatColumns.Parrentid, this.idSubcat, Condition.EQUAL, Condition.AND);
            ProductCatCollection _ProductCatCollection = ProductCatService.GetProductCatListByParam(ProductCat._Table + "." + ProductCatColumns.ProCateID, OrderDirection.ASC, cri.Criter);

            if (_ProductCatCollection.Count > 0)
            {
                foreach (ProductCat _ProductCat in _ProductCatCollection)
                {
                    qrycat += _ProductCat.ProCateID + ",";
                }
            }
            #region  Get Not gold Member
            Criteria crit = new Criteria();
            crit.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            crit.add(Member._Table + "." + MemberColumns.GoldMember, 0, Condition.EQUAL, Condition.AND);
            string sqry = "";
            if (qrycat != "")
            {
                if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                    sqry = crit.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
                else
                    sqry = crit.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
            }
            else
                sqry = crit.Criter + "And PRODUCTSELL.CatId IN(0)";
            ProductSellCollection _ProductSellCollectionNotGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqry, out OutTotalNotGold);
            #endregion
            #region  Get gold Member
            Criteria critr = new Criteria();
            critr.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            critr.add(Member._Table + "." + MemberColumns.GoldMember, 1, Condition.EQUAL, Condition.AND);
            string sqryr = "";
            if (qrycat != "")
            {
                if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                    sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
                else
                    sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
            }
            else
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(0)";
            _ProductSellCollectionGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqryr, out OutTotal);
            if (ckgoldmember.Checked == false)
            {
                for (int i = 0; i < _ProductSellCollectionNotGold.Count; i++)
                {
                    _ProductSellCollectionGold.Add(_ProductSellCollectionNotGold[i]);
                }
                OutTotal = OutTotal + OutTotalNotGold;
            }
            #endregion
        }
        if (this.idSubSubcat != long.MinValue)
        {
            #region  Get Not gold Member
            Criteria crit = new Criteria();
            crit.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            crit.add(Member._Table + "." + MemberColumns.GoldMember, 0, Condition.EQUAL, Condition.AND);
            crit.add(ProductSell._Table + "." + ProductSellColumns.CatId, this.idSubSubcat, Condition.EQUAL, Condition.AND);
            string sqry = "";
            if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                sqry = crit.Criter + "And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
            else
                sqry = crit.Criter;
            ProductSellCollection _ProductSellCollectionNotGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqry, out OutTotalNotGold);
            #endregion
            #region  Get gold Member
            Criteria critr = new Criteria();
            critr.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);

            critr.addJoin(ADESSA.Entities.Company._Table, Member._Table + "." + MemberColumns.MemberID, ADESSA.Entities.Company._Table + "." + CompanyColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
            critr.addJoin(Country._Table, ADESSA.Entities.Company._Table + "." + CompanyColumns.Country, Country._Table + "." + CountryColumns.CountryId, Condition.EQUAL, Condition.LEFT_JOIN);
            if (country != long.MinValue)
                critr.add(Country._Table + "." + CountryColumns.CountryId, country, Condition.EQUAL, Condition.AND);


            critr.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
            critr.add(Member._Table + "." + MemberColumns.GoldMember, 1, Condition.EQUAL, Condition.AND);
            critr.add(ProductSell._Table + "." + ProductSellColumns.CatId, this.idSubSubcat, Condition.EQUAL, Condition.AND);
            string sqryr = "";
            if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                sqryr = critr.Criter + "And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
            else
                sqryr = critr.Criter;
            _ProductSellCollectionGold = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, hyperlinkPager.CurrentIndex, hyperlinkPager.PageSize, sqryr, out OutTotal);
            if (ckgoldmember.Checked == false)
            {
                for (int i = 0; i < _ProductSellCollectionNotGold.Count; i++)
                {
                    _ProductSellCollectionGold.Add(_ProductSellCollectionNotGold[i]);
                }
                OutTotal = OutTotal + OutTotalNotGold;
            }
            #endregion
        }
        rptProductSell.DataSource = _ProductSellCollectionGold;
        rptProductSell.DataBind();
        hyperlinkPager.ItemCount = OutTotal;
        if ((float)OutTotal / (float)hyperlinkPager.PageSize <= 1)
            hyperlinkPager.Visible = false;
        else
            hyperlinkPager.Visible = true;

        LoadCountryCount();
    }
    protected void rptProductSell_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ProductSell _ProductSell = (ProductSell)e.Item.DataItem;
            HtmlAnchor hrfProdetailimg = (HtmlAnchor)e.Item.FindControl("hrfProdetailimg");
            HtmlImage imgPro = (HtmlImage)e.Item.FindControl("imgPro");
            HtmlAnchor hrfProdetail = (HtmlAnchor)e.Item.FindControl("hrfProdetail");
            Literal ltrTitle = (Literal)e.Item.FindControl("ltrTitle");
            Literal ltrListingDescription = (Literal)e.Item.FindControl("ltrListingDescription");
            Literal ltrMinOrder = (Literal)e.Item.FindControl("ltrMinOrder");
            Literal ltrFOBPrice = (Literal)e.Item.FindControl("ltrFOBPrice");
            HtmlAnchor hrfCompany = (HtmlAnchor)e.Item.FindControl("hrfCompany");
            Literal ltrTitleCompany = (Literal)e.Item.FindControl("ltrTitleCompany");
            Literal ltrTitleCompanyTyle = (Literal)e.Item.FindControl("ltrTitleCompanyTyle");
            HtmlImage imgflag = (HtmlImage)e.Item.FindControl("imgflag");
            Literal ltrContryName = (Literal)e.Item.FindControl("ltrContryName");
            HtmlImage imggold = (HtmlImage)e.Item.FindControl("imggold");
            Literal ltrMemberTyle = (Literal)e.Item.FindControl("ltrMemberTyle");
            HtmlImage imgyahoo = (HtmlImage)e.Item.FindControl("imgyahoo");
            Literal ltryahoo = (Literal)e.Item.FindControl("ltryahoo");
            HtmlAnchor hryahoo = (HtmlAnchor)e.Item.FindControl("hryahoo");
            HtmlAnchor hrfcontact = (HtmlAnchor)e.Item.FindControl("hrfcontact");
            //hrfProdetailimg.HRef = "ProductSellDetail.aspx?Id=" + _ProductSell.ProductId + "";
            hrfProdetailimg.HRef = "ProductsellDetail-" + _ProductSell.ProductId + "-" + Utilitys.StripDiacritics(Utility.Splitword(_ProductSell.Title)) + ".aspx";
            if (!string.IsNullOrEmpty(_ProductSell.Image))
                imgPro.Src = "photos/" + _ProductSell.Image;
            //hrfProdetail.HRef = "ProductSellDetail.aspx?Id=" + _ProductSell.ProductId + "";
            hrfProdetail.HRef = "ProductsellDetail-" + _ProductSell.ProductId + "-" + Utilitys.StripDiacritics(Utility.Splitword(_ProductSell.Title)) + ".aspx";
            ltrTitle.Text = _ProductSell.Title;
            ltrListingDescription.Text = _ProductSell.ProductDescription;
            ADESSA.Entities.UnitType _UnitType = UnitTypeService.GetUnitType(_ProductSell.MinQuantityTypeId);
            string MinOtherQuantity = " Other " + _ProductSell.MinQuantityOther;
            if (_UnitType != null)
            {
                ltrMinOrder.Text = _ProductSell.MinOrderQuantity + " " + _UnitType.Name + MinOtherQuantity;
            }
            UnitPrice _UnitPrice = UnitPriceService.GetUnitPrice(_ProductSell.FOBPriceId);
            string strUnitPrice = "";
            if (_UnitPrice != null)
                strUnitPrice = _UnitPrice.Title;
            ADESSA.Entities.UnitType _UnitType1 = UnitTypeService.GetUnitType(_ProductSell.PerTypeId);
            string strUnitType = "";
            if (_UnitType1 != null)
                strUnitType = _UnitType1.Name;
            ltrFOBPrice.Text = strUnitPrice + " " + _ProductSell.PriceSmall + " - " + _ProductSell.PriceLarge + " " + strUnitType;
            #region Load about company
            Member _Member = MemberService.GetMember(_ProductSell.MemberId);
            Criteria cri = new Criteria();
            cri.add(CompanyColumns.MemberID, _Member.MemberID, Condition.EQUAL, Condition.AND);
            CompanyCollection _CompanyCollection = CompanyService.GetCompanyListByParam(CompanyColumns.CompanyID, OrderDirection.ASC, cri.Criter);
            hrfCompany.HRef = "miniweb/Default.aspx?id=" + _CompanyCollection[0].CompanyID + "";
            ltrTitleCompany.Text = _CompanyCollection[0].CompanyName;
            Criteria crit = new Criteria();
            crit.add(CompanyAndTypeComColumns.CompanyID, _CompanyCollection[0].CompanyID, Condition.EQUAL, Condition.AND);
            CompanyAndTypeComCollection _CompanyAndTypeComCollection = CompanyAndTypeComService.GetCompanyAndTypeComListByParam(CompanyAndTypeComColumns.CompanyAndTypeComID, OrderDirection.ASC, crit.Criter);
            string TitleCompanyTyle = "";
            if (_CompanyAndTypeComCollection.Count > 0)
            {
                for (int i = 0; i < _CompanyAndTypeComCollection.Count; i++)
                {
                    TypeCompany _TypeCompany = TypeCompanyService.GetTypeCompany(_CompanyAndTypeComCollection[i].TypeComID);
                    TitleCompanyTyle += _TypeCompany.Title + ", ";
                }
            }
            ltrTitleCompanyTyle.Text = TitleCompanyTyle;

            Dictionary<string, string> thelist = new Dictionary<string, string>();
            Country _Country = CountryService.GetCountry(_CompanyCollection[0].Country);
            if (!string.IsNullOrEmpty(_Country.Img))
            {
                imgflag.Src = "photos/" + _Country.Img;
                ltrContryName.Text = _Country.Name;
                try
                {
                    thelist.Add(_Country.CountryId.ToString(), ",");
                    str += _Country.CountryId.ToString() + ",";
                }
                catch (Exception)
                {
                }
            }
            if (_Member.GoldMember == true)
            {
                ltrMemberTyle.Text = "Gold Member";
            }
            else
            {
                imggold.Visible = false;
                ltrMemberTyle.Text = " Free Member";
            }
            ltryahoo.Text = _Member.Other;
            if (!string.IsNullOrEmpty(_Member.Other))
            {
                if (_Member.Status == true)
                {
                    if (Utility.GetYahooStatus(_Member.Other))
                    {
                        imgyahoo.Src = "images/icon_online.png";
                    }
                    else
                    {
                        imgyahoo.Src = "images/icon_offline.png";
                    }
                    hryahoo.HRef = "ymsgr:sendIM?" + (_Member.Other);
                }
                else
                {
                    if (Utility.GetYahooStatus(_Member.Other))
                    {
                        imgyahoo.Src = "images/skype.png";
                    }
                    else
                    {
                        imgyahoo.Src = "images/skype_off.png";
                    }
                    hryahoo.HRef = "skype://" + _Member.Other + "?chat";
                }
            }


            #endregion
        }
    }
    #region Load country count Product
    private void LoadCountryCount()
    {
        Criteria cri = new Criteria();
        string strcout = "";
        if (!string.IsNullOrEmpty(str.TrimEnd(',')))
        {
            strcout = cri.Criter + "AND CountryId IN(" + str.TrimEnd(',') + ")";
        }
        else
        {
            cri.add(CountryColumns.CountryId, 0, Condition.EQUAL, Condition.AND);
            strcout = cri.Criter;
        }
        CountryCollection _CountryCollection = CountryService.GetCountryListByParam(CountryColumns.CountryId, OrderDirection.ASC, strcout);
        ArrayList _ArrayList = new ArrayList();
        ArrayList _ArrayList1 = new ArrayList();
        for (int i = 0; i < _CountryCollection.Count; i++)
        {
            if (i < 20)
            {
                _ArrayList.Add(_CountryCollection[i]);
            }
            else
            {
                _ArrayList1.Add(_CountryCollection[i]);
            }
        }
        rptcountrycount.DataSource = _ArrayList;
        rptcountrycount.DataBind();
        rptCountryOther.DataSource = _ArrayList1;
        rptCountryOther.DataBind();
    }
    protected void rptcountrycount_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Country _Country = (Country)e.Item.DataItem;
        Literal ltrsubsubcat = (Literal)e.Item.FindControl("ltrsubsubcat");
        HtmlAnchor hrfSubSubcat = (HtmlAnchor)e.Item.FindControl("hrfSubSubcat");
        Literal ltrcount = (Literal)e.Item.FindControl("ltrcount");
        HtmlImage img = (HtmlImage)e.Item.FindControl("img");
        if (!string.IsNullOrEmpty(_Country.Img))
            img.Src = "photos/" + _Country.Img;
        hrfSubSubcat.HRef = string.Format("ProductSearchSell.aspx?key={0}&country={1}&idcat={2}", key, _Country.CountryId, this.idcat);
        ltrsubsubcat.Text = _Country.Name;

        Criteria critr = new Criteria();
        critr.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(ADESSA.Entities.Company._Table, Member._Table + "." + MemberColumns.MemberID, ADESSA.Entities.Company._Table + "." + CompanyColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(Country._Table, ADESSA.Entities.Company._Table + "." + CompanyColumns.Country, Country._Table + "." + CountryColumns.CountryId, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.add(Country._Table + "." + CountryColumns.CountryId, _Country.CountryId, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
        if (ckgoldmember.Checked == true)
        {
            critr.add(Member._Table + "." + MemberColumns.GoldMember, 1, Condition.EQUAL, Condition.AND);
        }
        string sqryr = "";
        if (qrycat != "")
        {
            if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
            else
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
        }
        else
            sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(0)";
        ProductSellCollection _ProductSellCollectionGoldCount = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, sqryr);
        ltrcount.Text = _ProductSellCollectionGoldCount.Count.ToString();

    }
    protected void rptCountryOther_OnItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Country _Country = (Country)e.Item.DataItem;
        Literal ltrsubsubcat = (Literal)e.Item.FindControl("ltrsubsubcat");
        HtmlAnchor hrfSubSubcat = (HtmlAnchor)e.Item.FindControl("hrfSubSubcat");
        Literal ltrcount = (Literal)e.Item.FindControl("ltrcount");
        HtmlImage img = (HtmlImage)e.Item.FindControl("img");
        if (!string.IsNullOrEmpty(_Country.Img))
            img.Src = "photos/" + _Country.Img;
        hrfSubSubcat.HRef = string.Format("ProductSearchSell.aspx?key={0}&country={1}&idcat={2}", key, _Country.CountryId, this.idcat);
        ltrsubsubcat.Text = _Country.Name;

        Criteria critr = new Criteria();
        critr.addJoin(ProductCat._Table, ProductSell._Table + "." + ProductSellColumns.CatId, ProductCat._Table + "." + ProductCatColumns.ProCateID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(Member._Table, ProductSell._Table + "." + ProductSellColumns.MemberId, Member._Table + "." + MemberColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(ADESSA.Entities.Company._Table, Member._Table + "." + MemberColumns.MemberID, ADESSA.Entities.Company._Table + "." + CompanyColumns.MemberID, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.addJoin(Country._Table, ADESSA.Entities.Company._Table + "." + CompanyColumns.Country, Country._Table + "." + CountryColumns.CountryId, Condition.EQUAL, Condition.LEFT_JOIN);
        critr.add(Country._Table + "." + CountryColumns.CountryId, _Country.CountryId, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Enable, 1, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Approved, 1, Condition.EQUAL, Condition.AND);
        critr.add(ProductSell._Table + "." + ProductSellColumns.Not_Clear, 0, Condition.EQUAL, Condition.AND);
        if (ckgoldmember.Checked == true)
        {
            critr.add(Member._Table + "." + MemberColumns.GoldMember, 1, Condition.EQUAL, Condition.AND);
        }
        string sqryr = "";
        if (qrycat != "")
        {
            if (!string.IsNullOrEmpty(qryMember.TrimEnd(',')))
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ") And PRODUCTSELL.MemberId IN(" + qryMember.TrimEnd(',') + ")";
            else
                sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(" + qrycat.TrimEnd(',') + ")";
        }
        else
            sqryr = critr.Criter + "And PRODUCTSELL.CatId IN(0)";
        ProductSellCollection _ProductSellCollectionGoldCount = ProductSellService.GetProductSellListByParam(ProductSell._Table + "." + ProductSellColumns.CreatedDate, OrderDirection.DESC, sqryr);
        ltrcount.Text = _ProductSellCollectionGoldCount.Count.ToString();

    }
    #endregion
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndx = Convert.ToInt32(e.CommandArgument);
        hyperlinkPager.CurrentIndex = currnetPageIndx;
        LoadProductSell();
    }
    protected void ckgoldmember_OnCheckedChanged(object sender, EventArgs e)
    {
        if (ckgoldmember.Checked == true)
        {
            Goldmember = "true";
        }
        else
            Goldmember = "";
        LoadProductSell();
    }
    protected void ckonline_OnCheckedChanged(object sender, EventArgs e)
    {
        if (ckonline.Checked == true)
            Online = "true";
        else
            Online = "";
        LoadProductSell();
    }
    protected void page1_OnClick(object sender, EventArgs e)
    {
        PageSize = 10;
        LoadProductSell();
    }
    protected void page2_OnClick(object sender, EventArgs e)
    {
        PageSize = 20;
        LoadProductSell();
    }
    protected void page3_OnClick(object sender, EventArgs e)
    {
        PageSize = 40;
        LoadProductSell();
    }
    protected void btngotopage_OnClick(object sender, EventArgs e)
    {
        hyperlinkPager.CurrentIndex = Convert.ToInt32(txtgotopage.Value);
        LoadProductSell();
    }
    #endregion

}
